

function clearForm(form) {
    // iterate over all of the inputs for the form
    // element that was passed in
    $(':input', form).each(function() {
        var type = this.type;
        var tag = this.tagName.toLowerCase(); // normalize case
        // it's ok to reset the value attr of text inputs,
        // password inputs, and textareas
        if (type == 'text' || type == 'password' || tag == 'textarea')
            this.value = "";
        // checkboxes and radios need to have their checked state cleared
        // but should *not* have their 'value' changed
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        // select elements need to have their 'selectedIndex' property set to -1
        // (this works for both single and multiple select elements)
        else if (tag == 'select')
            this.selectedIndex = -1;
    });
}
;



$.fn.clearForm = function() {
    // iterate each matching form
    return this.each(function() {
        // iterate the elements within the form
        $(':input', this).each(function() {
            var type = this.type, tag = this.tagName.toLowerCase();
            if (type == 'text' || type == 'password' || tag == 'textarea')
                this.value = '';
            else if (type == 'checkbox' || type == 'radio')
                this.checked = false;
            else if (tag == 'select')
                this.selectedIndex = -1;
        });
    });
};



$.fn.clearForm = function() {
    return this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form')
            return $(':input', this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea')
            this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
    });
};

//datePicker
$(document).ready(function() {
    $(".datepicker").datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: "-90:+10",
        dateFormat: 'dd/mm/yy',
        dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado'],
        dayNamesMin: ['D','S','T','Q','Q','S','S','D'],
        dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
        monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
        monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez']
        
        
        
        
    });
       
    $('#datetimepicker1').datetimepicker({
        language: 'pt-BR'
    });

       
    $('.input-mask-phone').mask('(99) 999-9999');
     $('.input-mask-hora').mask('99:99');

    //dataTable de ordenação e estilo de tabela
    $(document).ready(function() {
        $('.dataTable').dataTable();
    });


    $(function() {

        $("select[name=atendimento_esmalte_id]").change(function() {
            esmalte = $(this).val();

            if (esmalte === '')
                return false;

            resetaCombo('atendimento_servico_id');

            $.getJSON(path + 'atendimento_c/getServicos/' + esmalte, function(data) {

                var option = new Array();

                $.each(data, function(i, obj) {

                    option[i] = document.createElement('option');
                    $(option[i]).attr({
                        value: obj.id
                    });
                    $(option[i]).append(obj.nome);
                    
                    $("select[name='atendimento_servico_id']").append(option[i]);
                   
                });

            });

        }); 

    });


    //Select dos serviços
    $(function() {

        $("select[name=atendimento_servico_id]").change(function() {
            servico = $(this).val();

            if (servico === '')
                return false;
            
            $.getJSON(path + 'atendimento_c/getValorServicos/' + servico, function(data) {
                
                label = document.createElement('label');
                $.each(data, function(i, obj) {
                    var  teste = obj.valor;
                    $("#teste").empty();
                    $("#teste").append(obj.nome +": "+ teste +  " Reais <br>");
                });
            });
        
        
        }); 

    });


    function resetaCombo(el) {
        $("select[name='" + el + "']").empty();
        var option = document.createElement('option');
        $(option).attr({
            value: ''
        });
        $(option).append('Escolha um servico');
        $("select[name='" + el + "']").append(option);
    }


    //Hide div w/id extra
    $("#DivDinheiro").css("display", "none");
    $("#DivDebito").css("display", "none");
    $("#DivCredito").css("display", "none");
    $("#divEntrada").css("display", "none");
    $("#divEnvelope").css("display", "none");
    $("#divSaida").css("display", "none");
      
      
      
    $("#Entrada").click(function() {
        // If checked
       
        //show the hidden div
        $("#divEntrada").css("display", "block");
        $("#divSaida").css("display", "none");
        $("#divEnvelope").css("display", "none");
        
  
    });
    
    $("#Saida").click(function() {
        // If checked
       
        //show the hidden div
        $("#divEntrada").css("display", "none");
        $("#divSaida").css("display", "block");
        $("#divEnvelope").css("display", "none");
        
  
    });
    
    $("#Envelope").click(function() {
        // If checked
       
        //show the hidden div
        $("#divEntrada").css("display", "none");
        $("#divSaida").css("display", "none");
        $("#divEnvelope").css("display", "block");
        
  
    });
      
      
      
      

    // Add onclick handler to checkbox w/id additional_contacts
    $("#tpDinheiro").click(function() {
        // If checked
        if ($("#tpDinheiro").is(":checked"))
        {
            //show the hidden div
            $("#DivDinheiro").css("display", "block");
        }
        else
        {
            //otherwise, hide it
            $("#DivDinheiro").css("display", "none");
        }
    });

    $("#tpDebito").click(function() {
        // If checked
        if ($("#tpDebito").is(":checked"))
        {
            //show the hidden div
            $("#DivDebito").css("display", "block");
        }
        else
        {
            //otherwise, hide it
            $("#DivDebito").css("display", "none");
        }


    });


    $("#tpCredito").click(function() {
        // If checked
        if ($("#tpCredito").is(":checked"))
        {
            //show the hidden div
            $("#DivCredito").css("display", "block");
        }
        else
        {
            //otherwise, hide it
            $("#DivCredito").css("display", "none");
        }


    });



});

